package org.airline.action;

import java.util.List;

import javax.annotation.Resource;

import org.airline.common.IModuleName;
import org.airline.entity.Flight;
import org.airline.entity.FlightArrange;
import org.airline.entity.PageBean;
import org.airline.service.FlightArrangeService;
import org.airline.service.FlightInfoService;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

@Component("FlightArrangeAction")
@SuppressWarnings("all")
public class FlightArrangeAction extends SuperAction{
	
	private String forwardURL;
	private FlightArrangeService flightArrangeService;
	private FlightInfoService flightService;
	private FlightArrange flightArrange;
	private List<FlightArrange> flightArrangeList;
	private int page = 1;
	private int pageSize = 10;
	private PageBean pageBean;
	private List<Flight> flightList;
	private int id;
	private Flight flight;
	private String startDate = "";
	private String keyWord;
	
	
	//航班信息录入
	public String FlightArrangeInput() throws Exception{
		try{
		    this.flightArrangeService.FlightArrangInfoSave(flightArrange);	
		}catch(Exception e){
			e.printStackTrace();
		}
		forwardURL = "ArrangeInfo!getAllArrangeInfo";
		return "Arrange";
	}
	
	//删除航班安排
	public String deleteFlightArrangeInfoById() throws Exception{
		try{
			this.flightArrangeService.deleteFlightArrangeInfoById(id);
		}catch(Exception e){
			e.printStackTrace();
		}
		forwardURL = "ArrangeInfo!getAllArrangeInfo";
		return "Arrange";
	}
	
	// 后台根据航班名称查询
	public String getFlightArrangeByKeyWord() throws Exception {
		try {
			pageBean = flightArrangeService.queryForPageByKeyWords(keyWord, pageSize, page);
		} catch (Exception e) {
		}
		forwardURL = "/admin/showBackTickets.jsp";
		return "success";
	}
	
	//更新航班安排
	public String updateFlightArrangeInfo() throws Exception{
		try{
			this.flightArrangeService.updateFlightArrangeInfo(flightArrange);
		}catch(Exception e){
			e.printStackTrace();
		}
		forwardURL = "ArrangeInfo!getAllArrangeInfo";
		return "Arrange";
	}
	
	public String preFlightArrangeInfo() throws Exception {
		try {
			this.flightList = this.flightService.getAllFlight();
		} catch (Exception e) {
			e.printStackTrace();
		}
		forwardURL = "/admin/arrangeFlight.jsp";
		return SUCCESS;
	}
	
	// 通过ID获取航班安排信息
	public String getFlightArrangeInfoById() throws Exception{
		try {
			this.flightArrange = this.flightArrangeService.getFlightArrangeById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		forwardURL = "/admin/updateArrange.jsp";
		return SUCCESS;
	}
	
	// 搜索航班安排分页显示
	public String searchForTickets() throws Exception {
		try {
			flightArrange.setStartDate(startDate);
			pageBean = flightArrangeService.querySearchForSingle(pageSize, page, flightArrange);
		} catch (Exception e) {
			logFailureString(IModuleName.GET, IModuleName.GET, "搜索航班安排失败", e);
			e.printStackTrace();
		}
		logSuccessString(IModuleName.GET, IModuleName.GET, "搜索航班安排成功");
		forwardURL = "/jsp/showAllTickets.jsp";
		return SUCCESS;
	}
	
	
	// 前台分页
	public String getAllFlightArrangeInfo() throws Exception {
		try {
			pageBean = flightArrangeService.queryForPage(pageSize, page);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		forwardURL = "/jsp/showAllTickets.jsp";
		return "success";
	}
	
	// 后台获取所有航班安排信息
	public String getAllArrangeInfo() throws Exception {
		try {
			pageBean = flightArrangeService.queryForPage(pageSize, page);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		forwardURL = "/admin/showBackTickets.jsp";
		return "success";
	}
	
	public String getForwardURL() {
		return forwardURL;
	}
	public void setForwardURL(String forwardURL) {
		this.forwardURL = forwardURL;
	}
	public FlightArrangeService getFlightArrangeService() {
		return flightArrangeService;
	}
	@Resource(name="FlightArrangeService")
	public void setFlightArrangeService(FlightArrangeService flightArrangeService) {
		this.flightArrangeService = flightArrangeService;
	}
	public FlightArrange getFlightArrange() {
		return flightArrange;
	}
	public void setFlightArrange(FlightArrange flightArrange) {
		this.flightArrange = flightArrange;
	}
	public List<FlightArrange> getFlightArrangeList() {
		return flightArrangeList;
	}
	public void setFlightArrangeList(List<FlightArrange> flightArrangeList) {
		this.flightArrangeList = flightArrangeList;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

	public List<Flight> getFlightList() {
		return flightList;
	}

	public void setFlightList(List<Flight> flightList) {
		this.flightList = flightList;
	}

	public Flight getFlight() {
		return flight;
	}

	public void setFlight(Flight flight) {
		this.flight = flight;
	}

	public FlightInfoService getFlightService() {
		return flightService;
	}

	@Resource(name = "FlightInfoService")
	public void setFlightService(FlightInfoService flightService) {
		this.flightService = flightService;
	}

	public PageBean getPageBean() {
		return pageBean;
	}

	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public String getKeyWord() {
		return keyWord;
	}

	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}
 
}
